/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import init.Config;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Antoine Boulinguez et Shyn-Yuan Cheng
 */
public class FileDiscoveryUtil {
    
    public static List<File> listFiles(File f, FilenameFilter filter) {
        List<File> fileList = new ArrayList<File>();

        if (f.isDirectory()) {
            for (File f1 : f.listFiles(filter)) {
                if (f1.isDirectory()) {
                    fileList.addAll(listFiles(f1, filter));
                } else {
                    fileList.add(f1);
                }
            }
        }

        return fileList;
    }
    
    public static List<File> listMp3sFrom(File f) {
         FileFilter filter = new FileFilter(".mp3");
         List<File> fileList = listFiles(f, filter);
         
         return fileList;
    }

    public static void main(String[] args) {
        File baseFile = new File(Config.MP3_BASE_DIRECTORY);
        List<File> fileList = listMp3sFrom(baseFile);
        
        System.out.println("Nombre de fichiers : " + fileList.size());
        for (File f : fileList) {
            System.out.println(f.getAbsolutePath());
        }
    }
}
